package cn.stylefeng.guns.modular.cb.controller;

import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.cb.entity.CbFocusCollection;
import cn.stylefeng.guns.modular.cb.model.params.CbFocusCollectionParam;
import cn.stylefeng.guns.modular.cb.service.CbFocusCollectionService;
import cn.stylefeng.roses.core.base.controller.BaseController;
import cn.stylefeng.roses.kernel.model.response.ResponseData;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;


/**
 * 控制器
 *
 * @author ss
 * @Date 2021-01-19 19:43:23
 */
@Controller
@RequestMapping("/cbFocusCollection")
public class CbFocusCollectionController extends BaseController {

    private static Logger logger = LoggerFactory.getLogger(CbFocusCollectionController.class);

    private String PREFIX = "/cb/cbFocusCollection";

    @Autowired
    private CbFocusCollectionService cbFocusCollectionService;
    /**
     * 跳转到主页面
     *
     * @author ss
     * @Date 2021-01-19
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "/cbFocusCollection.html";
    }

    /**
     * 新增页面
     *
     * @author ss
     * @Date 2021-01-19
     */
    @RequestMapping("/add")
    public String add() {
        return PREFIX + "/cbFocusCollection_add.html";
    }

    /**
     * 编辑页面
     *
     * @author ss
     * @Date 2021-01-19
     */
    @RequestMapping("/edit")
    public String edit() {
        return PREFIX + "/cbFocusCollection_edit.html";
    }

    /**
     * 新增接口
     *
     * @author ss
     * @Date 2021-01-19
     */
    @RequestMapping("/addItem")
    @ResponseBody
    public ResponseData addItem(CbFocusCollectionParam cbFocusCollectionParam) {
        //重构
        this.cbFocusCollectionService.addFocusCollection(cbFocusCollectionParam);
        return ResponseData.success();
    }

    /**
     * 编辑接口
     *
     * @author ss
     * @Date 2021-01-19
     */
    @RequestMapping("/editItem")
    @ResponseBody
    public ResponseData editItem(CbFocusCollectionParam cbFocusCollectionParam) {
        this.cbFocusCollectionService.update(cbFocusCollectionParam);
        return ResponseData.success();
    }

    /**
     * 删除接口
     *
     * @author ss
     * @Date 2021-01-19
     */
    @RequestMapping("/delete")
    @ResponseBody
    public ResponseData delete(CbFocusCollectionParam cbFocusCollectionParam) {
        //todo
        try{
            this.cbFocusCollectionService.deleteByUserIdAndObjectId(cbFocusCollectionParam);
        }catch (Exception e) {
            logger.error("delete focus or collection error: ", e);
        }
        return ResponseData.success();
    }

    /**
     * 查看详情接口
     *
     * @author ss
     * @Date 2021-01-19
     */
    @RequestMapping("/detail")
    @ResponseBody
    public ResponseData detail(CbFocusCollectionParam cbFocusCollectionParam) {
        CbFocusCollection detail = this.cbFocusCollectionService.getById(cbFocusCollectionParam.getId());
        return ResponseData.success(detail);
    }

    /**
     * 查询列表
     *
     * @author ss
     * @Date 2021-01-19
     */
    @ResponseBody
    @RequestMapping("/list")
    public LayuiPageInfo list(CbFocusCollectionParam cbFocusCollectionParam) {
        return this.cbFocusCollectionService.findPageBySpec(cbFocusCollectionParam);
    }

    /**
     * 查询列表
     *
     * @author ss
     * @Date 2021-01-19
     */
    @ResponseBody
    @RequestMapping("/getFousList")
    public LayuiPageInfo getFousList(CbFocusCollectionParam cbFocusCollectionParam) {
        return this.cbFocusCollectionService.getFocusList(cbFocusCollectionParam);
    }



    /**
     * 查询列表
     *
     * @author ss
     * @Date 2021-01-19
     */
    @ResponseBody
    @RequestMapping("/getFansList")
    public LayuiPageInfo getFansList(CbFocusCollectionParam cbFocusCollectionParam) {
        return this.cbFocusCollectionService.getFansList(cbFocusCollectionParam);
    }
    /**
     * 员工关注列表
     *
     * @author ss
     * @Date 2021-01-19
     */
    @ResponseBody
    @RequestMapping("/getStaffFocusList")
    public LayuiPageInfo getStaffFocusList(CbFocusCollectionParam cbFocusCollectionParam) {
        return this.cbFocusCollectionService.getStaffFocusList(cbFocusCollectionParam);
    }



    /**
     * 员工获取粉丝列表
     *
     * @author ss
     * @Date 2021-01-19
     */
    @ResponseBody
    @RequestMapping("/getStaffFansList")
    public LayuiPageInfo getStaffFansList(CbFocusCollectionParam cbFocusCollectionParam) {
        return this.cbFocusCollectionService.getStaffFansList(cbFocusCollectionParam);
    }
    /**
     * 查询收藏职位列表
     *
     * @author ss
     * @Date 2021-01-19
     */
    @ResponseBody
    @RequestMapping("/getCollectionPositionList")
    public LayuiPageInfo getCollectionPositionList(CbFocusCollectionParam cbFocusCollectionParam) {
        return this.cbFocusCollectionService.getCollectionPositionList(cbFocusCollectionParam);
    }

    /**
     * 粉丝数量
     * @return
     */
    @ResponseBody
    @RequestMapping("/get_fans_count")
    public ResponseData getFansCount(CbFocusCollectionParam cbFocusCollectionParam){
        Integer focus = cbFocusCollectionService.getFocusCollectionCount(cbFocusCollectionParam);
        return ResponseData.success(focus);
    }

}


